package tms.unitTests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;

import java.util.Calendar;
import java.util.Date;

import org.junit.Before;
import org.junit.Test;

import tms.model.DependencyManager;
import tms.model.Task;
import tms.model.TaskTree;

/**
 * DependencyManagerTests class contains the units tests of the methods in the DependencyManager class 
 * 
 * @author Rolf Schmidt
 *
 */
public class DependencyManagerUnitTests {

	/**
	 * helper method called before every unit test to clear the DependencyManager
	 */
	@Before
	public void setUp() {
		DependencyManager.getInstance().clear();
		TaskTree.getInstance().clear();
	}
	
	/**
	 * test that the only instance of the dependency manager is not null 
	 * and that it contains no person object
	 */
	@Test
	public void testDependencyManagerGetInstance1() {
		DependencyManager dependencyManager = DependencyManager.getInstance();
		assertNotNull(dependencyManager);
		assertTrue(dependencyManager.getDependencyMap().isEmpty());
    }
	
	/**
	 * test that the getInstance() always returns the same instance of the dependencyManager no matter how
	 * many times it is called
	 */
	@Test
	public void testDependencyManagerGetInstance2() {
		DependencyManager dependencyManager1 = DependencyManager.getInstance();
		DependencyManager dependencyManager2 = DependencyManager.getInstance();
		DependencyManager dependencyManager3 = DependencyManager.getInstance();
		
		assertNotNull(dependencyManager1);
		assertSame(dependencyManager1, dependencyManager2);
		assertSame(dependencyManager1, dependencyManager3);
    }

	/**
	 * test that two null objects cannot be added to the dependencyManager
	 * as a dependency
	 */
	@Test
	public void testDependencyManagerAddDependency1() {
		DependencyManager dependencyManager = DependencyManager.getInstance();
		
		dependencyManager.addDependency(null, null);
		assertEquals(0, dependencyManager.getDependencyMap().size());
    }
	
	/**
	 * test that the task, task dependency cannot be added to the dependencyManager
	 */
	@Test
	public void testDependencyManagerAddDependency2() {
		DependencyManager dependencyManager = DependencyManager.getInstance();
		
		Task task = new Task();
		
		dependencyManager.addDependency(task, task);
		assertEquals(0, dependencyManager.getDependencyMap().size());
    }
	
	/**
	 * test that a task without a dependency can be added to the dependencyManager
	 */
	@Test
	public void testDependencyManagerAddDependency3() {
		DependencyManager dependencyManager = DependencyManager.getInstance();
		
		Task task1 = new Task();
		Task task2 = new Task();
		task2.setId(1);

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());

		dependencyManager.addDependency(task1, task2);
		assertEquals(1, dependencyManager.getDependencyMap().size());
		assertTrue(dependencyManager.getDependencyMap().containsKey(task1.getId()));
    }
	
	/**
	 * test that a task with a dependency can be added to the dependencyManager by
	 * removing the prior dependency
	 */
	@Test
	public void testDependencyManagerAddDependency4() {
		DependencyManager dependencyManager = DependencyManager.getInstance();
		
		Task task1 = new Task();
		Task task2 = new Task();
		task2.setId(1);
		Task task3 = new Task();
		task3.setId(2);

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());
		assertEquals(2, task3.getId());

		dependencyManager.addDependency(task1, task2);
		assertEquals(1, dependencyManager.getDependencyMap().size());
		assertTrue(dependencyManager.getDependencyMap().containsKey(task1.getId()));
		int secondId1 = dependencyManager.getDependencyMap().get(task1.getId());
		assertEquals(1, secondId1);
		
		dependencyManager.addDependency(task1, task3);
		assertEquals(1, dependencyManager.getDependencyMap().size());
		assertTrue(dependencyManager.getDependencyMap().containsKey(task1.getId()));
		int secondId2 = dependencyManager.getDependencyMap().get(task1.getId());
		assertEquals(2, secondId2);
    }
	
	/**
	 * test that a null task cannot be removed from the dependencyManager
	 */
	@Test
	public void testDependencyManagerRemoveDependency1() {
		DependencyManager dependencyManager = DependencyManager.getInstance();

		dependencyManager.removeDependency(null);
		assertEquals(0, dependencyManager.getDependencyMap().size());
    }

	/**
	 * test that the same dependency cannot be removed twice from the
	 * dependencyManager
	 */
	@Test
	public void testDependencyManagerRemoveDependency2() {
		DependencyManager dependencyManager = DependencyManager.getInstance();

		Task task1 = new Task();
		Task task2 = new Task();
		task2.setId(1);

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());

		dependencyManager.addDependency(task1, task2);
		assertEquals(1, dependencyManager.getDependencyMap().size());

		dependencyManager.removeDependency(task1);
		assertEquals(0, dependencyManager.getDependencyMap().size());

		dependencyManager.removeDependency(task1);
		assertEquals(0, dependencyManager.getDependencyMap().size());
	}

	/**
	 * test that a task that does not have a dependency cannot be removed from the
	 * dependencyManager
	 */
	@Test
	public void testDependencyManagerRemoveDependency3() {
		DependencyManager dependencyManager = DependencyManager.getInstance();

		Task task1 = new Task();
		Task task2 = new Task();
		task2.setId(1);
		Task task3 = new Task();
		task3.setId(2);

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());

		dependencyManager.addDependency(task1, task2);
		assertEquals(1, dependencyManager.getDependencyMap().size());

		dependencyManager.removeDependency(task3);
		assertEquals(1, dependencyManager.getDependencyMap().size());
	}

	/**
	 * test when a task with a dependency is removed from the dependencyManager
	 */
	@Test
	public void testDependencyManagerRemoveDependency4() {
		DependencyManager dependencyManager = DependencyManager.getInstance();

		Task task1 = new Task();
		Task task2 = new Task();
		task2.setId(1);

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());

		dependencyManager.addDependency(task1, task2);
		assertEquals(1, dependencyManager.getDependencyMap().size());

		dependencyManager.removeDependency(task1);
		assertEquals(0, dependencyManager.getDependencyMap().size());
	}

	/**
	 * test for circular dependency on an empty dependency map and a null Task
	 * 
	 * expect false
	 */
	@Test
	public void testDependencyManagerIsCircular1() {
		DependencyManager dependencyManager = DependencyManager.getInstance();

		Object params[] = new Object[1];
		params[0] = null;

		Boolean isCircular = (Boolean) PrivateAccessor.getPrivateMethod(dependencyManager, "isCircular", params);
		assertTrue(!isCircular);
	}

	/**
	 * test for circular dependency on an empty dependency map and a valid Task
	 * 
	 * expect false
	 */
	@Test
	public void testDependencyManagerIsCircular2() {
		DependencyManager dependencyManager = DependencyManager.getInstance();
		TaskTree taskTree = TaskTree.getInstance();
		
		Task task1 = taskTree.addTask();
		
		Object params[] = new Object[1];
		params[0] = task1;

		Boolean isCircular = (Boolean) PrivateAccessor.getPrivateMethod(dependencyManager, "isCircular", params);
		assertTrue(!isCircular);
	}

	/**
	 * test for circular dependency when a circular dependency does not exist but the Task argument
	 * has a dependency
	 * 
	 * expect false
	 */
	@Test
	public void testDependencyManagerIsCircular3() {
		DependencyManager dependencyManager = DependencyManager.getInstance();
		TaskTree taskTree = TaskTree.getInstance();
		
		Task task1 = taskTree.addTask();
		Task task2 = taskTree.addTask();

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());
		task1.setBeforeId(1);

		dependencyManager.addDependency(task1, task2);

		Object params[] = new Object[1];
		params[0] = task1;

		Boolean isCircular = (Boolean) PrivateAccessor.getPrivateMethod(dependencyManager, "isCircular", params);
		assertTrue(!isCircular);
	}

	/**
	 * test for circular dependency when a circular dependency does not exist and the Task argument
	 * does not have a dependency
	 * 
	 * expect false
	 */
	@Test
	public void testDependencyManagerIsCircular4() {
		DependencyManager dependencyManager = DependencyManager.getInstance();
		TaskTree taskTree = TaskTree.getInstance();
		
		Task task1 = taskTree.addTask();
		Task task2 = taskTree.addTask();
		Task task3 = taskTree.addTask();

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());
		assertEquals(2, task3.getId());
		task1.setBeforeId(1);

		dependencyManager.addDependency(task1, task2);

		Object params[] = new Object[1];
		params[0] = task3;

		Boolean isCircular = (Boolean) PrivateAccessor.getPrivateMethod(dependencyManager, "isCircular", params);
		assertTrue(!isCircular);
	}

	/**
	 * test for circular dependency when a circular dependency exists
	 * 
	 * expect true
	 */
	@Test
	public void testDependencyManagerIsCircular5() {
		DependencyManager dependencyManager = DependencyManager.getInstance();
		TaskTree taskTree = TaskTree.getInstance();
		
		Task task1 = taskTree.addTask();
		Task task2 = taskTree.addTask();

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());
		task1.setBeforeId(1);
		task2.setBeforeId(0);

		dependencyManager.addDependency(task1, task2);
		dependencyManager.addDependency(task2, task1);

		Object params[] = new Object[1];
		params[0] = task1;

		Boolean isCircular = (Boolean) PrivateAccessor.getPrivateMethod(dependencyManager, "isCircular", params);
		assertTrue(isCircular);
	}

	/**
	 * resolve overlaps on an empty dependency map (i.e. no overlaps exist)
	 */
	@Test
	public void testDependencyManagerResolveOverlaps1() {
		DependencyManager dependencyManager = DependencyManager.getInstance();
		TaskTree taskTree = TaskTree.getInstance();
		
		Task task1 = taskTree.addTask();
		Task task2 = taskTree.addTask();

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());
		
		Date task1Deadline = task1.getDeadline();
		Date task2Deadline = task2.getDeadline();
		
		PrivateAccessor.getPrivateMethod(dependencyManager, "resolveOverlaps", null);
		assertTrue(dependencyManager.getDependencyMap().isEmpty());
		assertEquals(task1Deadline, task1.getDeadline());
		assertEquals(task2Deadline, task2.getDeadline());
	}

	/**
	 * resolve overlaps when no overlaps exist, but the dependencyManager is not empty
	 */
	@Test
	public void testDependencyManagerResolveOverlaps2() {
		DependencyManager dependencyManager = DependencyManager.getInstance();
		TaskTree taskTree = TaskTree.getInstance();
		
		Task task1 = taskTree.addTask();
		Task task2 = taskTree.addTask();

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());
		
		Date task1Deadline = task1.getDeadline();
		
		Calendar endDateTask2 = Calendar.getInstance();
		endDateTask2.setTime(task1Deadline);
		endDateTask2.add(Calendar.MONTH, 1);
		
		Date task2Deadline = endDateTask2.getTime();
		task2.setDeadline(task2Deadline);

		task1.setBeforeId(1);
		
		dependencyManager.addDependency(task1, task2);
		
		PrivateAccessor.getPrivateMethod(dependencyManager, "resolveOverlaps", null);
		assertEquals(1, dependencyManager.getDependencyMap().size());
		assertEquals(task1Deadline, task1.getDeadline());
		assertEquals(task2Deadline, task2.getDeadline());
	}

	/**
	 * resolve overlaps when one overlap exists due to a deadline conflict without
	 * chaining dependencies
	 */
	@Test
	public void testDependencyManagerResolveOverlaps3() {
		DependencyManager dependencyManager = DependencyManager.getInstance();
		TaskTree taskTree = TaskTree.getInstance();
		
		Task task1 = taskTree.addTask();
		Task task2 = taskTree.addTask();
		Task task3 = taskTree.addTask();
		Task task4 = taskTree.addTask();

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());
		assertEquals(2, task3.getId());
		assertEquals(3, task4.getId());

		Date task1Deadline = task1.getDeadline();
		Date task2Deadline = task2.getDeadline();

		task1.setBeforeId(1);
		task3.setBeforeId(3);
		
		dependencyManager.addDependency(task1, task2);
		dependencyManager.addDependency(task3, task4);
		
		PrivateAccessor.getPrivateMethod(dependencyManager, "resolveOverlaps", null);
		assertEquals(2, dependencyManager.getDependencyMap().size());
		assertEquals(task1Deadline, task1.getDeadline());
		assertTrue(task2Deadline.before(task2.getDeadline()));
		assertTrue(task1.getDeadline().before(task2.getDeadline()));
	}

	/**
	 * resolve overlaps when one overlap exists due to a duration conflict without
	 * chaining dependencies
	 */
	@Test
	public void testDependencyManagerResolveOverlaps4() {
		DependencyManager dependencyManager = DependencyManager.getInstance();
		TaskTree taskTree = TaskTree.getInstance();
		
		Task task1 = taskTree.addTask();
		Task task2 = taskTree.addTask();

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());
		
		Date task1Deadline = task1.getDeadline();
		
		Calendar endDateTask2 = Calendar.getInstance();
		endDateTask2.setTime(task1Deadline);
		endDateTask2.add(Calendar.DAY_OF_MONTH, 1);
		
		Date task2Deadline = endDateTask2.getTime();
		task2.setDeadline(task2Deadline);
		
		task2.setDuration(20);

		task1.setBeforeId(1);
		
		dependencyManager.addDependency(task1, task2);
		
		PrivateAccessor.getPrivateMethod(dependencyManager, "resolveOverlaps", null);
		assertEquals(1, dependencyManager.getDependencyMap().size());
		assertEquals(task1Deadline, task1.getDeadline());
		assertTrue(task2Deadline.before(task2.getDeadline()));
		assertTrue(task1.getDeadline().before(task2.getDeadline()));
	}

	/**
	 * resolve overlaps when two overlaps exists without chaining dependencies
	 */
	@Test
	public void testDependencyManagerResolveOverlaps5() {
		DependencyManager dependencyManager = DependencyManager.getInstance();
		TaskTree taskTree = TaskTree.getInstance();
		
		Task task1 = taskTree.addTask();
		Task task2 = taskTree.addTask();
		Task task3 = taskTree.addTask();
		Task task4 = taskTree.addTask();

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());
		assertEquals(2, task3.getId());
		assertEquals(3, task4.getId());

		Date task1Deadline = task1.getDeadline();
		Date task2Deadline = task2.getDeadline();
		Date task3Deadline = task3.getDeadline();
		Date task4Deadline = task4.getDeadline();

		task1.setBeforeId(1);
		task3.setBeforeId(3);
		
		dependencyManager.addDependency(task1, task2);
		dependencyManager.addDependency(task3, task4);
		
		PrivateAccessor.getPrivateMethod(dependencyManager, "resolveOverlaps", null);
		assertEquals(2, dependencyManager.getDependencyMap().size());
		assertEquals(task1Deadline, task1.getDeadline());
		assertTrue(task2Deadline.before(task2.getDeadline()));
		assertTrue(task1.getDeadline().before(task2.getDeadline()));
		
		assertEquals(task3Deadline, task3.getDeadline());
		assertTrue(task4Deadline.before(task4.getDeadline()));
		assertTrue(task3.getDeadline().before(task4.getDeadline()));
	}
	/**
	 * resolve overlaps when two overlaps exists without chaining dependencies
	 */
	@Test
	public void testDependencyManagerResolveOverlaps6() {
		DependencyManager dependencyManager = DependencyManager.getInstance();
		TaskTree taskTree = TaskTree.getInstance();
		
		Task task1 = taskTree.addTask();
		Task task2 = taskTree.addTask();
		Task task3 = taskTree.addTask();
		Task task4 = taskTree.addTask();

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());
		assertEquals(2, task3.getId());
		assertEquals(3, task4.getId());

		Date task1Deadline = task1.getDeadline();
		Date task2Deadline = task2.getDeadline();
		Date task3Deadline = task3.getDeadline();

		task1.setBeforeId(1);
		task2.setBeforeId(2);
		
		dependencyManager.addDependency(task1, task2);
		dependencyManager.addDependency(task2, task3);
		
		PrivateAccessor.getPrivateMethod(dependencyManager, "resolveOverlaps", null);
		assertEquals(2, dependencyManager.getDependencyMap().size());
		assertEquals(task1Deadline, task1.getDeadline());
		assertTrue(task1.getDeadline().before(task2.getDeadline()));
		assertTrue(task2.getDeadline().before(task3.getDeadline()));
		assertTrue(task2Deadline.before(task2.getDeadline()));
		assertTrue(task3Deadline.before(task3.getDeadline()));
	}

	/**
	 * resolve dependencies on an empty dependency map (i.e. no dependencies exist)
	 */
	@Test
	public void testDependencyManagerResolveDependencies1() {
		DependencyManager dependencyManager = DependencyManager.getInstance();

		Object params[] = new Object[2];
		params[0] = null;
		params[1] = -1;
		
		PrivateAccessor.getPrivateMethod(dependencyManager, "resolveDependencies", params);
		assertTrue(dependencyManager.getDependencyMap().isEmpty());
	}

	/**
	 * resolve dependencies when no dependencies exist, but the dependencyManager is not empty
	 */
	@Test
	public void testDependencyManagerResolveDependencies2() {
		DependencyManager dependencyManager = DependencyManager.getInstance();

		TaskTree taskTree = TaskTree.getInstance();
		
		Task task1 = taskTree.addTask();
		Task task2 = taskTree.addTask();

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());

		task1.setBeforeId(1);

		dependencyManager.addDependency(task1, task2);
		
		Object params[] = new Object[2];
		params[0] = null;
		params[1] = -1;
		
		PrivateAccessor.getPrivateMethod(dependencyManager, "resolveDependencies", params);

		assertEquals(1, dependencyManager.getDependencyMap().size());
		assertTrue(dependencyManager.getDependencyMap().containsKey(task1.getId()));
		int secondId1 = dependencyManager.getDependencyMap().get(task1.getId());
		assertEquals(1, secondId1);
	}

	/**
	 * resolve dependencies when dependencies exist and the Task argument will not create
	 * a dependency
	 */
	@Test
	public void testDependencyManagerResolveDependencies3() {
		DependencyManager dependencyManager = DependencyManager.getInstance();

		TaskTree taskTree = TaskTree.getInstance();
		
		Task task1 = taskTree.addTask();
		Task task2 = taskTree.addTask();
		Task task3 = taskTree.addTask();
		
		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());
		assertEquals(2, task3.getId());
		
		task1.setBeforeId(1);

		dependencyManager.addDependency(task1, task2);
		
		Object params[] = new Object[2];
		params[0] = task3;
		params[1] = -1;
		
		PrivateAccessor.getPrivateMethod(dependencyManager, "resolveDependencies", params);

		assertEquals(1, dependencyManager.getDependencyMap().size());
		assertTrue(dependencyManager.getDependencyMap().containsKey(task1.getId()));
		int secondId1 = dependencyManager.getDependencyMap().get(task1.getId());
		assertEquals(1, secondId1);
	}

	/**
	 * resolve dependencies when dependencies exist and the Task argument will create
	 * a dependency (no prior dependency)
	 */
	@Test
	public void testDependencyManagerResolveDependencies4() {
		DependencyManager dependencyManager = DependencyManager.getInstance();

		TaskTree taskTree = TaskTree.getInstance();
		
		Task task1 = taskTree.addTask();
		Task task2 = taskTree.addTask();
		Task task3 = taskTree.addTask();

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());
		assertEquals(2, task3.getId());

		task1.setBeforeId(1);
		task3.setBeforeId(1);

		dependencyManager.addDependency(task1, task2);
		dependencyManager.addDependency(task3, task1);
		
		Object params[] = new Object[2];
		params[0] = task3;
		params[1] = -1;
		
		PrivateAccessor.getPrivateMethod(dependencyManager, "resolveDependencies", params);

		assertEquals(2, dependencyManager.getDependencyMap().size());
		assertTrue(dependencyManager.getDependencyMap().containsKey(task1.getId()));
		int secondId1 = dependencyManager.getDependencyMap().get(task1.getId());
		assertEquals(1, secondId1);
		assertTrue(dependencyManager.getDependencyMap().containsKey(task3.getId()));
		int secondId2 = dependencyManager.getDependencyMap().get(task3.getId());
		assertEquals(1, secondId2);
	}

	/**
	 * resolve dependencies when dependencies exist and the Task argument will create
	 * a dependency (prior dependency)
	 */
	@Test
	public void testDependencyManagerResolveDependencies5() {
		DependencyManager dependencyManager = DependencyManager.getInstance();

		TaskTree taskTree = TaskTree.getInstance();
		
		Task task1 = taskTree.addTask();
		Task task2 = taskTree.addTask();
		Task task3 = taskTree.addTask();

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());
		assertEquals(2, task3.getId());

		task1.setBeforeId(1);
		task3.setBeforeId(0);

		dependencyManager.addDependency(task1, task2);
		dependencyManager.addDependency(task3, task2);
		
		Object params[] = new Object[2];
		params[0] = task3;
		params[1] = 1;
		
		PrivateAccessor.getPrivateMethod(dependencyManager, "resolveDependencies", params);

		assertEquals(2, dependencyManager.getDependencyMap().size());
		assertTrue(dependencyManager.getDependencyMap().containsKey(task1.getId()));
		int secondId1 = dependencyManager.getDependencyMap().get(task1.getId());
		assertEquals(1, secondId1);
		assertTrue(dependencyManager.getDependencyMap().containsKey(task3.getId()));
		int secondId2 = dependencyManager.getDependencyMap().get(task3.getId());
		assertEquals(0, secondId2);
		assertEquals(0, task3.getBeforeId());
	}

	/**
	 * resolve dependencies when dependencies exist and the Task argument will create
	 * a circular dependency (no prior dependency)
	 */
	@Test
	public void testDependencyManagerResolveDependencies6() {
		DependencyManager dependencyManager = DependencyManager.getInstance();

		TaskTree taskTree = TaskTree.getInstance();
		
		Task task1 = taskTree.addTask();
		Task task2 = taskTree.addTask();

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());

		task1.setBeforeId(1);
		task2.setBeforeId(0);

		dependencyManager.addDependency(task1, task2);
		dependencyManager.addDependency(task2, task1);
		
		Object params[] = new Object[2];
		params[0] = task2;
		params[1] = -1;
		
		PrivateAccessor.getPrivateMethod(dependencyManager, "resolveDependencies", params);

		assertEquals(1, dependencyManager.getDependencyMap().size());
		assertTrue(dependencyManager.getDependencyMap().containsKey(task1.getId()));
		int secondId1 = dependencyManager.getDependencyMap().get(task1.getId());
		assertEquals(1, secondId1);
		assertTrue(!dependencyManager.getDependencyMap().containsKey(task2.getId()));
		assertEquals(-1, task2.getBeforeId());
	}

	/**
	 * resolve dependencies when dependencies exist and the Task argument will create
	 * a circular dependency (prior dependency)
	 */
	@Test
	public void testDependencyManagerResolveDependencies7() {
		DependencyManager dependencyManager = DependencyManager.getInstance();

		TaskTree taskTree = TaskTree.getInstance();
		
		Task task1 = taskTree.addTask();
		Task task2 = taskTree.addTask();
		Task task3 = taskTree.addTask();

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());
		assertEquals(2, task3.getId());

		task1.setBeforeId(1);
		task2.setBeforeId(0);

		dependencyManager.addDependency(task1, task2);
		dependencyManager.addDependency(task2, task3);
		
		Object params[] = new Object[2];
		params[0] = task2;
		params[1] = 2;
		
		PrivateAccessor.getPrivateMethod(dependencyManager, "resolveDependencies", params);

		assertEquals(2, dependencyManager.getDependencyMap().size());
		assertTrue(dependencyManager.getDependencyMap().containsKey(task1.getId()));
		int secondId1 = dependencyManager.getDependencyMap().get(task1.getId());
		assertEquals(1, secondId1);
		assertTrue(dependencyManager.getDependencyMap().containsKey(task2.getId()));
		int secondId2 = dependencyManager.getDependencyMap().get(task2.getId());
		assertEquals(2, secondId2);
		assertEquals(2, task2.getBeforeId());
	}

	/**
	 * clear an empty dependencyManager
	 */
	@Test
	public void testDependencyManagerClear1() {
		DependencyManager dependencyManager = DependencyManager.getInstance();
		dependencyManager.clear();
		assertTrue(dependencyManager.getDependencyMap().isEmpty());
	}

	/**
	 * clear a non-empty empty dependencyManager
	 */
	@Test
	public void testDependencyManagerClear2() {
		DependencyManager dependencyManager = DependencyManager.getInstance();

		Task task1 = new Task();
		Task task2 = new Task();
		task2.setId(1);
		Task task3 = new Task();
		task3.setId(2);

		assertEquals(0, task1.getId());
		assertEquals(1, task2.getId());
		assertEquals(2, task3.getId());

		dependencyManager.addDependency(task1, task2);
		dependencyManager.addDependency(task2, task3);
		assertEquals(2, dependencyManager.getDependencyMap().size());

		dependencyManager.clear();
		assertTrue(dependencyManager.getDependencyMap().isEmpty());
	}

}
